import javax.swing.*;
import java.awt.*;

public class ChatInterface extends JFrame {
    private JTextField messageField;
    private JTextArea messageArea;

    public ChatInterface() {
        setTitle("即时通信软件");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        initUI();
    }

    private void initUI() {
        messageField = new JTextField(20);
        messageArea = new JTextArea(8, 20);
        messageArea.setEditable(false);

        JPanel northPanel = new JPanel();
        northPanel.add(new JLabel("消息："));
        northPanel.add(messageField);

        add(northPanel, BorderLayout.NORTH);
        add(new JScrollPane(messageArea), BorderLayout.CENTER);

        JButton sendButton = new JButton("发送");
        sendButton.addActionListener(e -> {
            String message = messageField.getText();
            // 这里添加发送消息的逻辑
            messageArea.append("你： " + message + "\n");
            messageField.setText("");
        });

        JPanel southPanel = new JPanel();
        southPanel.add(sendButton);
        add(southPanel, BorderLayout.SOUTH);
    }

    public static void main(String[] args) {
        ChatInterface chat = new ChatInterface();
        chat.setVisible(true);
    }
}
